home *** CD-ROM | disk | FTP | other *** search
- unit ClientMain;
-
- interface
-
- uses
- System.Drawing, System.Collections, System.ComponentModel,
- System.Windows.Forms, System.Data, System.Resources;
-
- type
- TMainForm = class(System.Windows.Forms.Form)
- {$REGION 'Designer Managed Code'}
- strict private
- /// <summary>
- /// Required designer variable.
- /// </summary>
- components: System.ComponentModel.IContainer;
- GroupBoxFrom: System.Windows.Forms.GroupBox;
- GroupBoxTo: System.Windows.Forms.GroupBox;
- TextBoxAddressFrom: System.Windows.Forms.TextBox;
- TextBoxCityFrom: System.Windows.Forms.TextBox;
- TextBoxStateFrom: System.Windows.Forms.TextBox;
- TextBoxAddressTo: System.Windows.Forms.TextBox;
- TextBoxCityTo: System.Windows.Forms.TextBox;
- TextBoxStateTo: System.Windows.Forms.TextBox;
- MainMenu: System.Windows.Forms.MainMenu;
- MenuItem1: System.Windows.Forms.MenuItem;
- MenuItemExit: System.Windows.Forms.MenuItem;
- Label1: System.Windows.Forms.Label;
- Label2: System.Windows.Forms.Label;
- Label3: System.Windows.Forms.Label;
- Label4: System.Windows.Forms.Label;
- Label5: System.Windows.Forms.Label;
- Label6: System.Windows.Forms.Label;
- StatusBar: System.Windows.Forms.StatusBar;
- MenuItem2: System.Windows.Forms.MenuItem;
- MenuItem3: System.Windows.Forms.MenuItem;
- MenuItemAbout: System.Windows.Forms.MenuItem;
- TabControl1: System.Windows.Forms.TabControl;
- TabPageDirections: System.Windows.Forms.TabPage;
- TabPageSoap: System.Windows.Forms.TabPage;
- TextBoxDirection: System.Windows.Forms.TextBox;
- MenuItem4: System.Windows.Forms.MenuItem;
- MenuItemDirection: System.Windows.Forms.MenuItem;
- TextBoxRequest: System.Windows.Forms.TextBox;
- TextBoxResponse: System.Windows.Forms.TextBox;
- ToolTip: System.Windows.Forms.ToolTip;
- Splitter2: System.Windows.Forms.Splitter;
- ImageList: System.Windows.Forms.ImageList;
- StatusBarPanel1: System.Windows.Forms.StatusBarPanel;
- MenuItemCopy: System.Windows.Forms.MenuItem;
- ToolBar1: System.Windows.Forms.ToolBar;
- ToolBarButton1: System.Windows.Forms.ToolBarButton;
- ToolBarButtonDirection: System.Windows.Forms.ToolBarButton;
- ToolBarButton3: System.Windows.Forms.ToolBarButton;
- ToolBarButtonCopy: System.Windows.Forms.ToolBarButton;
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- procedure InitializeComponent;
- procedure TMainForm_Load(sender: System.Object; e: System.EventArgs);
- procedure MenuItemExit_Click(sender: System.Object; e: System.EventArgs);
- procedure MenuItemDirection_Click(sender: System.Object; e: System.EventArgs);
- procedure MenuItemCopy_Click(sender: System.Object; e: System.EventArgs);
- procedure MenuItemAbout_Click(sender: System.Object; e: System.EventArgs);
- procedure ToolBar1_ButtonClick(sender: System.Object; e: System.Windows.Forms.ToolBarButtonClickEventArgs);
- {$ENDREGION}
- strict protected
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- procedure Dispose(Disposing: Boolean); override;
- private
- type
- TTextBoxTextDelegate = procedure (Control: TextBox; Content: string) of object;
- TExceptionHandlerDelegate = procedure (E: Exception) of object;
- private
- FSyncTextBoxes: TTextBoxTextDelegate;
- FWaitingForResult: Boolean;
- procedure SetWaitingForResult(const Value: Boolean);
- procedure Sync_TextBoxText(Control: TextBox; Content: string);
- public
- constructor Create;
- procedure GetDirectionsCallBack(Ar: IAsyncResult);
- procedure HandleException(E: Exception);
- procedure FindDirection;
- procedure MonitorSoapRequest(Sender: TObject; const Xml: string);
- procedure MonitorSoapResponse(Sender: TObject; const Xml: string);
- procedure UpdateStatusBar(const Text: string = '');
- property WaitingForResult: Boolean read FWaitingForResult write SetWaitingForResult;
- end;
-
- implementation
-
- uses
- System.Globalization, PetrVones.Utils.SoapTrace, borland.IMapQuestservice, AboutBox;
-
- resourcestring
- RsConnecting = 'Connecting to the server ...';
- RsError = 'There was an error during the call';
- RsGettingData = 'Getting the direction ...';
- RsInfo = 'Press F9 to get the directions';
-
-
- {$REGION 'Windows Form Designer generated code'}
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- procedure TMainForm.InitializeComponent;
- type
- TSystem_Windows_Forms_MenuItemArray = array of System.Windows.Forms.MenuItem;
- TSystem_Windows_Forms_StatusBarPanelArray = array of System.Windows.Forms.StatusBarPanel;
- TSystem_Windows_Forms_ToolBarButtonArray = array of System.Windows.Forms.ToolBarButton;
- var
- resources: System.Resources.ResourceManager;
- begin
- Self.components := System.ComponentModel.Container.Create;
- resources := System.Resources.ResourceManager.Create(TypeOf(TMainForm));
- Self.GroupBoxFrom := System.Windows.Forms.GroupBox.Create;
- Self.Label3 := System.Windows.Forms.Label.Create;
- Self.Label2 := System.Windows.Forms.Label.Create;
- Self.Label1 := System.Windows.Forms.Label.Create;
- Self.TextBoxStateFrom := System.Windows.Forms.TextBox.Create;
- Self.TextBoxCityFrom := System.Windows.Forms.TextBox.Create;
- Self.TextBoxAddressFrom := System.Windows.Forms.TextBox.Create;
- Self.GroupBoxTo := System.Windows.Forms.GroupBox.Create;
- Self.Label4 := System.Windows.Forms.Label.Create;
- Self.Label5 := System.Windows.Forms.Label.Create;
- Self.Label6 := System.Windows.Forms.Label.Create;
- Self.TextBoxStateTo := System.Windows.Forms.TextBox.Create;
- Self.TextBoxCityTo := System.Windows.Forms.TextBox.Create;
- Self.TextBoxAddressTo := System.Windows.Forms.TextBox.Create;
- Self.MainMenu := System.Windows.Forms.MainMenu.Create;
- Self.MenuItem1 := System.Windows.Forms.MenuItem.Create;
- Self.MenuItemDirection := System.Windows.Forms.MenuItem.Create;
- Self.MenuItem4 := System.Windows.Forms.MenuItem.Create;
- Self.MenuItemExit := System.Windows.Forms.MenuItem.Create;
- Self.MenuItem2 := System.Windows.Forms.MenuItem.Create;
- Self.MenuItemCopy := System.Windows.Forms.MenuItem.Create;
- Self.MenuItem3 := System.Windows.Forms.MenuItem.Create;
- Self.MenuItemAbout := System.Windows.Forms.MenuItem.Create;
- Self.StatusBar := System.Windows.Forms.StatusBar.Create;
- Self.StatusBarPanel1 := System.Windows.Forms.StatusBarPanel.Create;
- Self.ImageList := System.Windows.Forms.ImageList.Create(Self.components);
- Self.TabControl1 := System.Windows.Forms.TabControl.Create;
- Self.TabPageDirections := System.Windows.Forms.TabPage.Create;
- Self.TextBoxDirection := System.Windows.Forms.TextBox.Create;
- Self.TabPageSoap := System.Windows.Forms.TabPage.Create;
- Self.TextBoxRequest := System.Windows.Forms.TextBox.Create;
- Self.Splitter2 := System.Windows.Forms.Splitter.Create;
- Self.TextBoxResponse := System.Windows.Forms.TextBox.Create;
- Self.ToolTip := System.Windows.Forms.ToolTip.Create(Self.components);
- Self.ToolBar1 := System.Windows.Forms.ToolBar.Create;
- Self.ToolBarButton1 := System.Windows.Forms.ToolBarButton.Create;
- Self.ToolBarButtonDirection := System.Windows.Forms.ToolBarButton.Create;
- Self.ToolBarButton3 := System.Windows.Forms.ToolBarButton.Create;
- Self.ToolBarButtonCopy := System.Windows.Forms.ToolBarButton.Create;
- Self.GroupBoxFrom.SuspendLayout;
- Self.GroupBoxTo.SuspendLayout;
- (System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).BeginInit;
- Self.TabControl1.SuspendLayout;
- Self.TabPageDirections.SuspendLayout;
- Self.TabPageSoap.SuspendLayout;
- Self.SuspendLayout;
- //
- // GroupBoxFrom
- //
- Self.GroupBoxFrom.Controls.Add(Self.Label3);
- Self.GroupBoxFrom.Controls.Add(Self.Label2);
- Self.GroupBoxFrom.Controls.Add(Self.Label1);
- Self.GroupBoxFrom.Controls.Add(Self.TextBoxStateFrom);
- Self.GroupBoxFrom.Controls.Add(Self.TextBoxCityFrom);
- Self.GroupBoxFrom.Controls.Add(Self.TextBoxAddressFrom);
- Self.GroupBoxFrom.Location := System.Drawing.Point.Create(0, 32);
- Self.GroupBoxFrom.Name := 'GroupBoxFrom';
- Self.GroupBoxFrom.Size := System.Drawing.Size.Create(360, 72);
- Self.GroupBoxFrom.TabIndex := 3;
- Self.GroupBoxFrom.TabStop := False;
- Self.GroupBoxFrom.Text := 'Fro&m';
- //
- // Label3
- //
- Self.Label3.AutoSize := True;
- Self.Label3.Location := System.Drawing.Point.Create(264, 24);
- Self.Label3.Name := 'Label3';
- Self.Label3.Size := System.Drawing.Size.Create(31, 16);
- Self.Label3.TabIndex := 5;
- Self.Label3.Text := 'State';
- //
- // Label2
- //
- Self.Label2.AutoSize := True;
- Self.Label2.Location := System.Drawing.Point.Create(136, 24);
- Self.Label2.Name := 'Label2';
- Self.Label2.Size := System.Drawing.Size.Create(24, 16);
- Self.Label2.TabIndex := 4;
- Self.Label2.Text := 'City';
- //
- // Label1
- //
- Self.Label1.AutoSize := True;
- Self.Label1.Location := System.Drawing.Point.Create(8, 24);
- Self.Label1.Name := 'Label1';
- Self.Label1.Size := System.Drawing.Size.Create(46, 16);
- Self.Label1.TabIndex := 3;
- Self.Label1.Text := 'Address';
- //
- // TextBoxStateFrom
- //
- Self.TextBoxStateFrom.Location := System.Drawing.Point.Create(264, 40);
- Self.TextBoxStateFrom.Name := 'TextBoxStateFrom';
- Self.TextBoxStateFrom.Size := System.Drawing.Size.Create(88, 20);
- Self.TextBoxStateFrom.TabIndex := 2;
- Self.TextBoxStateFrom.Text := 'NY';
- //
- // TextBoxCityFrom
- //
- Self.TextBoxCityFrom.Location := System.Drawing.Point.Create(136, 40);
- Self.TextBoxCityFrom.Name := 'TextBoxCityFrom';
- Self.TextBoxCityFrom.Size := System.Drawing.Size.Create(120, 20);
- Self.TextBoxCityFrom.TabIndex := 1;
- Self.TextBoxCityFrom.Text := 'New York';
- //
- // TextBoxAddressFrom
- //
- Self.TextBoxAddressFrom.Location := System.Drawing.Point.Create(8, 40);
- Self.TextBoxAddressFrom.Name := 'TextBoxAddressFrom';
- Self.TextBoxAddressFrom.Size := System.Drawing.Size.Create(120, 20);
- Self.TextBoxAddressFrom.TabIndex := 0;
- Self.TextBoxAddressFrom.Text := '39th and 11th';
- //
- // GroupBoxTo
- //
- Self.GroupBoxTo.Controls.Add(Self.Label4);
- Self.GroupBoxTo.Controls.Add(Self.Label5);
- Self.GroupBoxTo.Controls.Add(Self.Label6);
- Self.GroupBoxTo.Controls.Add(Self.TextBoxStateTo);
- Self.GroupBoxTo.Controls.Add(Self.TextBoxCityTo);
- Self.GroupBoxTo.Controls.Add(Self.TextBoxAddressTo);
- Self.GroupBoxTo.Location := System.Drawing.Point.Create(376, 32);
- Self.GroupBoxTo.Name := 'GroupBoxTo';
- Self.GroupBoxTo.Size := System.Drawing.Size.Create(360, 72);
- Self.GroupBoxTo.TabIndex := 4;
- Self.GroupBoxTo.TabStop := False;
- Self.GroupBoxTo.Text := '&To';
- //
- // Label4
- //
- Self.Label4.AutoSize := True;
- Self.Label4.Location := System.Drawing.Point.Create(264, 24);
- Self.Label4.Name := 'Label4';
- Self.Label4.Size := System.Drawing.Size.Create(31, 16);
- Self.Label4.TabIndex := 8;
- Self.Label4.Text := 'State';
- //
- // Label5
- //
- Self.Label5.AutoSize := True;
- Self.Label5.Location := System.Drawing.Point.Create(136, 24);
- Self.Label5.Name := 'Label5';
- Self.Label5.Size := System.Drawing.Size.Create(24, 16);
- Self.Label5.TabIndex := 7;
- Self.Label5.Text := 'City';
- //
- // Label6
- //
- Self.Label6.AutoSize := True;
- Self.Label6.Location := System.Drawing.Point.Create(8, 24);
- Self.Label6.Name := 'Label6';
- Self.Label6.Size := System.Drawing.Size.Create(46, 16);
- Self.Label6.TabIndex := 6;
- Self.Label6.Text := 'Address';
- //
- // TextBoxStateTo
- //
- Self.TextBoxStateTo.Location := System.Drawing.Point.Create(264, 40);
- Self.TextBoxStateTo.Name := 'TextBoxStateTo';
- Self.TextBoxStateTo.Size := System.Drawing.Size.Create(80, 20);
- Self.TextBoxStateTo.TabIndex := 2;
- Self.TextBoxStateTo.Text := 'NY';
- //
- // TextBoxCityTo
- //
- Self.TextBoxCityTo.Location := System.Drawing.Point.Create(136, 40);
- Self.TextBoxCityTo.Name := 'TextBoxCityTo';
- Self.TextBoxCityTo.Size := System.Drawing.Size.Create(120, 20);
- Self.TextBoxCityTo.TabIndex := 1;
- Self.TextBoxCityTo.Text := 'New York';
- //
- // TextBoxAddressTo
- //
- Self.TextBoxAddressTo.Location := System.Drawing.Point.Create(8, 40);
- Self.TextBoxAddressTo.Name := 'TextBoxAddressTo';
- Self.TextBoxAddressTo.Size := System.Drawing.Size.Create(120, 20);
- Self.TextBoxAddressTo.TabIndex := 0;
- Self.TextBoxAddressTo.Text := '1535 Broadway';
- //
- // MainMenu
- //
- Self.MainMenu.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItem1, Self.MenuItem2, Self.MenuItem3));
- //
- // MenuItem1
- //
- Self.MenuItem1.Index := 0;
- Self.MenuItem1.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemDirection, Self.MenuItem4, Self.MenuItemExit));
- Self.MenuItem1.Text := '&File';
- //
- // MenuItemDirection
- //
- Self.MenuItemDirection.Index := 0;
- Self.MenuItemDirection.Shortcut := System.Windows.Forms.Shortcut.F9;
- Self.MenuItemDirection.Text := 'Get &directions';
- Include(Self.MenuItemDirection.Click, Self.MenuItemDirection_Click);
- //
- // MenuItem4
- //
- Self.MenuItem4.Index := 1;
- Self.MenuItem4.Text := '-';
- //
- // MenuItemExit
- //
- Self.MenuItemExit.Index := 2;
- Self.MenuItemExit.Text := 'E&xit';
- Include(Self.MenuItemExit.Click, Self.MenuItemExit_Click);
- //
- // MenuItem2
- //
- Self.MenuItem2.Index := 1;
- Self.MenuItem2.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemCopy));
- Self.MenuItem2.Text := 'Edit';
- //
- // MenuItemCopy
- //
- Self.MenuItemCopy.Index := 0;
- Self.MenuItemCopy.Shortcut := System.Windows.Forms.Shortcut.CtrlC;
- Self.MenuItemCopy.Text := 'Copy to clipboard';
- Include(Self.MenuItemCopy.Click, Self.MenuItemCopy_Click);
- //
- // MenuItem3
- //
- Self.MenuItem3.Index := 2;
- Self.MenuItem3.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemAbout));
- Self.MenuItem3.Text := 'Help';
- //
- // MenuItemAbout
- //
- Self.MenuItemAbout.Index := 0;
- Self.MenuItemAbout.Text := 'About';
- Include(Self.MenuItemAbout.Click, Self.MenuItemAbout_Click);
- //
- // StatusBar
- //
- Self.StatusBar.Location := System.Drawing.Point.Create(0, 628);
- Self.StatusBar.Name := 'StatusBar';
- Self.StatusBar.Panels.AddRange(TSystem_Windows_Forms_StatusBarPanelArray.Create(Self.StatusBarPanel1));
- Self.StatusBar.ShowPanels := True;
- Self.StatusBar.Size := System.Drawing.Size.Create(736, 22);
- Self.StatusBar.TabIndex := 5;
- //
- // StatusBarPanel1
- //
- Self.StatusBarPanel1.AutoSize := System.Windows.Forms.StatusBarPanelAutoSize.Spring;
- Self.StatusBarPanel1.Width := 720;
- //
- // ImageList
- //
- Self.ImageList.ColorDepth := System.Windows.Forms.ColorDepth.Depth4Bit;
- Self.ImageList.ImageSize := System.Drawing.Size.Create(16, 16);
- Self.ImageList.ImageStream := (System.Windows.Forms.ImageListStreamer(resources.GetObject('ImageList.ImageStream')));
- Self.ImageList.TransparentColor := System.Drawing.Color.White;
- //
- // TabControl1
- //
- Self.TabControl1.Anchor := (System.Windows.Forms.AnchorStyles((((System.Windows.Forms.AnchorStyles.Top
- or System.Windows.Forms.AnchorStyles.Bottom) or System.Windows.Forms.AnchorStyles.Left)
- or System.Windows.Forms.AnchorStyles.Right)));
- Self.TabControl1.Controls.Add(Self.TabPageDirections);
- Self.TabControl1.Controls.Add(Self.TabPageSoap);
- Self.TabControl1.Location := System.Drawing.Point.Create(0, 112);
- Self.TabControl1.Name := 'TabControl1';
- Self.TabControl1.SelectedIndex := 0;
- Self.TabControl1.Size := System.Drawing.Size.Create(736, 512);
- Self.TabControl1.TabIndex := 7;
- //
- // TabPageDirections
- //
- Self.TabPageDirections.Controls.Add(Self.TextBoxDirection);
- Self.TabPageDirections.Location := System.Drawing.Point.Create(4, 22);
- Self.TabPageDirections.Name := 'TabPageDirections';
- Self.TabPageDirections.Size := System.Drawing.Size.Create(728, 486);
- Self.TabPageDirections.TabIndex := 0;
- Self.TabPageDirections.Text := 'Directions';
- //
- // TextBoxDirection
- //
- Self.TextBoxDirection.Dock := System.Windows.Forms.DockStyle.Fill;
- Self.TextBoxDirection.Location := System.Drawing.Point.Create(0, 0);
- Self.TextBoxDirection.Multiline := True;
- Self.TextBoxDirection.Name := 'TextBoxDirection';
- Self.TextBoxDirection.ScrollBars := System.Windows.Forms.ScrollBars.Vertical;
- Self.TextBoxDirection.Size := System.Drawing.Size.Create(728, 486);
- Self.TextBoxDirection.TabIndex := 0;
- Self.TextBoxDirection.Text := '';
- //
- // TabPageSoap
- //
- Self.TabPageSoap.Controls.Add(Self.TextBoxRequest);
- Self.TabPageSoap.Controls.Add(Self.Splitter2);
- Self.TabPageSoap.Controls.Add(Self.TextBoxResponse);
- Self.TabPageSoap.Location := System.Drawing.Point.Create(4, 22);
- Self.TabPageSoap.Name := 'TabPageSoap';
- Self.TabPageSoap.Size := System.Drawing.Size.Create(728, 486);
- Self.TabPageSoap.TabIndex := 1;
- Self.TabPageSoap.Text := 'SOAP monitor';
- //
- // TextBoxRequest
- //
- Self.TextBoxRequest.Dock := System.Windows.Forms.DockStyle.Fill;
- Self.TextBoxRequest.Font := System.Drawing.Font.Create('Courier New', 8.25, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (Byte(238)));
- Self.TextBoxRequest.Location := System.Drawing.Point.Create(0, 0);
- Self.TextBoxRequest.Multiline := True;
- Self.TextBoxRequest.Name := 'TextBoxRequest';
- Self.TextBoxRequest.ScrollBars := System.Windows.Forms.ScrollBars.Both;
- Self.TextBoxRequest.Size := System.Drawing.Size.Create(728, 200);
- Self.TextBoxRequest.TabIndex := 1;
- Self.TextBoxRequest.Text := '';
- Self.ToolTip.SetToolTip(Self.TextBoxRequest, 'Request');
- Self.TextBoxRequest.WordWrap := False;
- //
- // Splitter2
- //
- Self.Splitter2.Dock := System.Windows.Forms.DockStyle.Bottom;
- Self.Splitter2.Location := System.Drawing.Point.Create(0, 200);
- Self.Splitter2.Name := 'Splitter2';
- Self.Splitter2.Size := System.Drawing.Size.Create(728, 8);
- Self.Splitter2.TabIndex := 3;
- Self.Splitter2.TabStop := False;
- //
- // TextBoxResponse
- //
- Self.TextBoxResponse.Dock := System.Windows.Forms.DockStyle.Bottom;
- Self.TextBoxResponse.Font := System.Drawing.Font.Create('Courier New', 8.25, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (Byte(238)));
- Self.TextBoxResponse.Location := System.Drawing.Point.Create(0, 208);
- Self.TextBoxResponse.Multiline := True;
- Self.TextBoxResponse.Name := 'TextBoxResponse';
- Self.TextBoxResponse.ScrollBars := System.Windows.Forms.ScrollBars.Both;
- Self.TextBoxResponse.Size := System.Drawing.Size.Create(728, 278);
- Self.TextBoxResponse.TabIndex := 2;
- Self.TextBoxResponse.Text := '';
- Self.ToolTip.SetToolTip(Self.TextBoxResponse, 'Response');
- Self.TextBoxResponse.WordWrap := False;
- //
- // ToolBar1
- //
- Self.ToolBar1.Buttons.AddRange(TSystem_Windows_Forms_ToolBarButtonArray.Create(Self.ToolBarButton1, Self.ToolBarButtonDirection, Self.ToolBarButton3, Self.ToolBarButtonCopy));
- Self.ToolBar1.DropDownArrows := True;
- Self.ToolBar1.ImageList := Self.ImageList;
- Self.ToolBar1.Location := System.Drawing.Point.Create(0, 0);
- Self.ToolBar1.Name := 'ToolBar1';
- Self.ToolBar1.ShowToolTips := True;
- Self.ToolBar1.Size := System.Drawing.Size.Create(736, 28);
- Self.ToolBar1.TabIndex := 8;
- Self.ToolBar1.Wrappable := False;
- Include(Self.ToolBar1.ButtonClick, Self.ToolBar1_ButtonClick);
- //
- // ToolBarButton1
- //
- Self.ToolBarButton1.Style := System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // ToolBarButtonDirection
- //
- Self.ToolBarButtonDirection.ImageIndex := 1;
- Self.ToolBarButtonDirection.ToolTipText := 'Get directions';
- //
- // ToolBarButton3
- //
- Self.ToolBarButton3.Style := System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // ToolBarButtonCopy
- //
- Self.ToolBarButtonCopy.ImageIndex := 0;
- Self.ToolBarButtonCopy.ToolTipText := 'Copy to clipboard';
- //
- // TMainForm
- //
- Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
- Self.ClientSize := System.Drawing.Size.Create(736, 650);
- Self.Controls.Add(Self.ToolBar1);
- Self.Controls.Add(Self.TabControl1);
- Self.Controls.Add(Self.StatusBar);
- Self.Controls.Add(Self.GroupBoxTo);
- Self.Controls.Add(Self.GroupBoxFrom);
- Self.Menu := Self.MainMenu;
- Self.MinimumSize := System.Drawing.Size.Create(744, 500);
- Self.Name := 'TMainForm';
- Self.Text := 'MapQuest web service client';
- Include(Self.Load, Self.TMainForm_Load);
- Self.GroupBoxFrom.ResumeLayout(False);
- Self.GroupBoxTo.ResumeLayout(False);
- (System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).EndInit;
- Self.TabControl1.ResumeLayout(False);
- Self.TabPageDirections.ResumeLayout(False);
- Self.TabPageSoap.ResumeLayout(False);
- Self.ResumeLayout(False);
- end;
- {$ENDREGION}
-
- procedure TMainForm.Dispose(Disposing: Boolean);
- begin
- if Disposing then
- begin
- if Components <> nil then
- Components.Dispose();
- end;
- inherited Dispose(Disposing);
- end;
-
- constructor TMainForm.Create;
- begin
- inherited Create;
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent;
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- end;
-
- // Reference:
- // http://bdn.borland.com/article/0,1410,28835,00.html
-
- procedure TMainForm.FindDirection;
- var
- MapQuest: IMapQuestservice;
- Ar: IAsyncResult;
- begin
- TextBoxRequest.Text := '';
- TextBoxResponse.Text := '';
- TextBoxDirection.Text := '';
- WaitingForResult := True;
- UpdateStatusBar(RsConnecting);
- Update;
- try
- MapQuest := IMapQuestservice.Create;
- UpdateStatusBar(RsGettingData);
- Ar := MapQuest.BeginGetDirections(TextBoxAddressFrom.Text, TextBoxCityFrom.Text, TextBoxStateFrom.Text, 'US',
- TextBoxAddressTo.Text, TextBoxCityTo.Text, TextBoxStateTo.Text, 'US', GetDirectionsCallBack, MapQuest);
- Assert(not Ar.CompletedSynchronously);
- except
- on E: Exception do
- HandleException(E);
- end;
- end;
-
- procedure TMainForm.GetDirectionsCallBack(Ar: IAsyncResult);
- var
- MapQuest: IMapQuestservice;
- Direction: string;
- begin
- MapQuest := IMapQuestservice(Ar.AsyncState);
- try
- Direction := MapQuest.EndGetDirections(Ar);
- Invoke(Delegate(@FSyncTextBoxes), [TextBoxDirection, Direction.Replace(#10, #13#10)]);
- except
- on E: Exception do
- HandleException(E);
- end;
- end;
-
- procedure TMainForm.HandleException(E: Exception);
- var
- Sync: TExceptionHandlerDelegate;
- begin
- if not InvokeRequired then
- begin
- WaitingForResult := False;
- UpdateStatusBar(RsError);
- MessageBox.Show(E.Message, 'Error', MessageBoxButtons.OK, MessageBoxIcon.Error);
- end
- else
- begin
- Sync := HandleException;
- Invoke(Delegate(@Sync), [E]);
- end;
- end;
-
- procedure TMainForm.SetWaitingForResult(const Value: Boolean);
- begin
- FWaitingForResult := Value;
- MenuItemDirection.Enabled := not Value;
- ToolBarButtonDirection.Enabled := not Value;
- if not Value then
- UpdateStatusBar('');
- end;
-
- procedure TMainForm.Sync_TextBoxText(Control: TextBox; Content: string);
- begin
- Control.Text := Content;
- Control.Update;
- if Control = TextBoxDirection then
- WaitingForResult := False;
- end;
-
- procedure TMainForm.MonitorSoapRequest(Sender: TObject; const Xml: string);
- begin
- Invoke(Delegate(@FSyncTextBoxes), [TextBoxRequest, TSoapMonitor.FormatXmlData(Xml)]);
- end;
-
- procedure TMainForm.MonitorSoapResponse(Sender: TObject; const Xml: string);
- begin
- Invoke(Delegate(@FSyncTextBoxes), [TextBoxResponse, TSoapMonitor.FormatXmlData(Xml)]);
- end;
-
- procedure TMainForm.UpdateStatusBar(const Text: string);
- begin
- StatusBarPanel1.Text := Text;
- StatusBar.Update;
- end;
-
- procedure TMainForm.ToolBar1_ButtonClick(sender: System.Object; e: System.Windows.Forms.ToolBarButtonClickEventArgs);
- begin
- if e.Button = ToolBarButtonDirection then
- MenuItemDirection_Click(sender, e)
- else
- if e.Button = ToolBarButtonCopy then
- MenuItemCopy_Click(sender, e);
- end;
-
- procedure TMainForm.MenuItemAbout_Click(sender: System.Object; e: System.EventArgs);
- begin
- TAboutBox.ShowAboutBox;
- end;
-
- procedure TMainForm.MenuItemCopy_Click(sender: System.Object; e: System.EventArgs);
- begin
- Clipboard.SetDataObject(TextBoxDirection.Text, True);
- end;
-
- procedure TMainForm.TMainForm_Load(sender: System.Object; e: System.EventArgs);
- begin
- FSyncTextBoxes := Sync_TextBoxText;
- Include(SoapMonitor.OnRequest, MonitorSoapRequest);
- Include(SoapMonitor.OnResponse, MonitorSoapResponse);
- UpdateStatusBar(RsInfo);
- end;
-
- procedure TMainForm.MenuItemDirection_Click(sender: System.Object; e: System.EventArgs);
- begin
- FindDirection;
- end;
-
- procedure TMainForm.MenuItemExit_Click(sender: System.Object; e: System.EventArgs);
- begin
- Application.Exit;
- end;
-
- end.
-
-
-
-